package io;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;

public class WriteStringDemo {
    public static void main(String[] args) throws IOException {
        //向文件fos.txt中写入字符串
        FileOutputStream fos = new FileOutputStream("fos.txt");

        String line = "窗外的麻雀, 电线杆上多嘴. ";
        //String提供了将字符串转换为一组字节的操作:getBytes()
        byte[] data = line.getBytes(StandardCharsets.UTF_8);
        fos.write(data);

        line = "你说这一句, 很有夏天的感觉";
        data = line.getBytes(StandardCharsets.UTF_8);
        fos.write(data);

        System.out.println("写出完毕");
    }
}
